package com.itheima06;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectDemo {
    public static void main(String[] args) {
        ArrayList<String> womanList = new ArrayList<String>();
        womanList.add("林青霞");
        womanList.add("张曼玉");
        womanList.add("王祖贤");
        womanList.add("柳岩");

        // 需求1：名字=3的流
//        womanList.stream().filter(s -> s.length() == 3).forEach(System.out::println);
        Stream<String> stringStream = womanList.stream().filter(s -> s.length() == 3);

        // 需求2：Stream操作完毕后，收集到新list中
        List<String> names = stringStream.collect(Collectors.toList());
        names.forEach(System.out::println);
        System.out.println("--------");


        Set<Integer> set = new HashSet<Integer>();
        set.add(10);
        set.add(20);
        set.add(30);
        set.add(33);
        set.add(35);

        // 需求3：> 25
        Stream<Integer> setStream = set.stream().filter(s -> s > 25);

        // 需求4：Stream操作完毕后，收集到新set中
        Set<Integer> ageSet = setStream.collect(Collectors.toSet());
        System.out.println("--------");


        String[] strings = {"林青霞,30","张曼玉,35","王祖贤,33","柳岩,25" };

        // 需求5：> 28
        Stream<String> stringStream1 = Stream.of(strings).filter(s -> Integer.parseInt(s.split(",")[1]) > 28);

        // 需求6：Stream操作完毕后，收集到新map中，姓名为键，年龄为值
        Map<String, Integer> nameMap = stringStream1.collect(Collectors.toMap(s -> s.split(",")[0], s -> Integer.parseInt(s.split(",")[1])));
        nameMap.entrySet().forEach(System.out::println);
    }
}
